<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="700px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
          <el-form-item label="订单号" prop="activityOrderNum">
            <el-input v-model="form.activityOrderNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="会员ID" prop="memberId">
            <el-input v-model="form.memberId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="活动ID" prop="activityId">
            <el-input v-model="form.activityId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="小组ID" prop="activityTeamId">
            <el-input v-model="form.activityTeamId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单金额" prop="activityOrderAmount">
            <el-input v-model="form.activityOrderAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付金额" prop="payAmount">
            <el-input v-model="form.payAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付时间" prop="payDate">
            <el-date-picker v-model="form.payDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="支付状态" prop="payStatus">
            <el-select v-model="form.payStatus" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.PAY_STATUS"
                :key="item.id"
                :label="item.label"
                :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="第三方支付凭证">
            <el-input v-model="form.transactionId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退款金额">
            <el-input v-model="form.refrundAmount" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退款时间">
            <el-date-picker v-model="form.refrundDate" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退款状态">
            <el-input v-model="form.refrundStatus" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="退款流水号">
            <el-input v-model="form.refrundNum" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('activityOrderNum')" prop="activityOrderNum" label="订单号" />
        <el-table-column v-if="columns.visible('applyName')" prop="applyName" label="报名姓名" />
        <el-table-column v-if="columns.visible('applyPhone')" prop="applyPhone" label="报名电话" />
        <el-table-column v-if="columns.visible('applySex')" prop="applySex" label="报名性别" />
        <el-table-column v-if="columns.visible('createTimeApply')" prop="createTimeApply" label="报名时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTimeApply) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('username')" prop="username" label="会员" />
        <el-table-column v-if="columns.visible('activityTitle')" prop="activityTitle" label="活动" />
        <el-table-column v-if="columns.visible('name')" prop="name" label="小组负责人" />
        <el-table-column v-if="columns.visible('activityOrderAmount')" prop="activityOrderAmount" label="订单金额" />
        <el-table-column v-if="columns.visible('payAmount')" prop="payAmount" label="支付金额" />
        <el-table-column v-if="columns.visible('payDate')" prop="payDate" label="支付时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('payStatus')" prop="payStatus" label="支付状态">
          <template slot-scope="scope">
            {{ dict.label.PAY_STATUS[scope.row.payStatus] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('transactionId')" prop="transactionId" label="支付凭证" />
        <el-table-column v-if="columns.visible('refrundAmount')" prop="refrundAmount" label="退款金额" />
        <el-table-column v-if="columns.visible('refrundDate')" prop="refrundDate" label="退款时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.refrundDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('refrundStatus')" prop="refrundStatus" label="退款状态">
          <template slot-scope="scope">
            {{ dict.label.REFRUND_STATUS[scope.row.refrundStatus] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('refrundNum')" prop="refrundNum" label="退款流水号" />

        <el-table-column v-permission="['admin','tanzerActivityOrder:edit','tanzerActivityOrder:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTanzerActivityOrder from '@/api/tanzer/tanzerActivityOrder'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import MaterialList from "@/components/material";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '活动订单表', url: 'api/tanzerActivityOrder', sort: 'id,desc', crudMethod: { ...crudTanzerActivityOrder }})
const defaultForm = { id: null, activityOrderNum: null, memberId: null, activityId: null, activityTeamId: null, activityOrderAmount: null, payAmount: null, payDate: null, payStatus: null, transactionId: null, refrundAmount: null, refrundDate: null, refrundStatus: null, refrundNum: null, isDel: null, createTime: null, createBy: null, updateBy: null, updateTime: null }
export default {
  name: 'TanzerActivityOrder',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['PAY_STATUS', 'REFRUND_STATUS'],
  data() {
    return {

      permission: {
        add: ['admin', 'tanzerActivityOrder:add'],
        edit: ['admin', 'tanzerActivityOrder:edit'],
        del: ['admin', 'tanzerActivityOrder:del']
      },
      rules: {
        activityOrderNum: [
          { required: true, message: '订单号不能为空', trigger: 'blur' }
        ],
        memberId: [
          { required: true, message: '会员ID不能为空', trigger: 'blur' }
        ],
        activityId: [
          { required: true, message: '活动ID不能为空', trigger: 'blur' }
        ],
        activityTeamId: [
          { required: true, message: '小组ID不能为空', trigger: 'blur' }
        ],
        activityOrderAmount: [
          { required: true, message: '订单金额不能为空', trigger: 'blur' }
        ],
        payAmount: [
          { required: true, message: '支付金额不能为空', trigger: 'blur' }
        ],
        payDate: [
          { required: true, message: '支付时间不能为空', trigger: 'blur' }
        ],
        payStatus: [
          { required: true, message: '支付状态不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'id', display_name: '表ID，主键，供其他表做外键' },
        { key: 'activityOrderNum', display_name: '订单号' },
        { key: 'memberId', display_name: '会员ID' },
        { key: 'activityId', display_name: '活动ID' },
        { key: 'activityTeamId', display_name: '小组ID' },
        { key: 'activityOrderAmount', display_name: '订单金额' },
        { key: 'payAmount', display_name: '支付金额' },
        { key: 'payStatus', display_name: '支付状态' },
        { key: 'refrundStatus', display_name: '退款状态' },
        { key: 'refrundNum', display_name: '退款流水号' }
      ]
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }else{
        delete this.crud.params.id
        delete this.crud.params.activityOrderNum
        delete this.crud.params.memberId
        delete this.crud.params.activityId
        delete this.crud.params.activityTeamId
        delete this.crud.params.activityOrderAmount
        delete this.crud.params.payAmount
        delete this.crud.params.payStatus
        delete this.crud.params.refrundStatus
        delete this.crud.params.refrundNum
      }
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
